package com.jiazhong.basic.pack0316.thread.work01;

public class Window implements Runnable {

    private Train train;

    public Window(Train train) {
        this.train = train;
    }

    @Override
    public void run() {
        String name = Thread.currentThread().getName();
        while (true) {
            int time = (int) (Math.random() * 3000 + 100);
            try {
                Thread.sleep(time);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            String buy = train.buy();
            if (buy == null) {
                System.out.println("票已卖完");
                break;
            }
            System.out.println(name + "购买了：" + buy);
        }
    }
}
